#ifndef MESH3D_H
#define MESH3D_H

#include <iterator>
#include <fmt/core.h>
#include <fmt/format.h>

#include "base.h"
#include "utils.h"
#include "geo3d.h"
#include "GeoGrid.h"
#include "GRDECLData.h"

class Mesh3D {
public:
    Mesh3D(GeoGrid &grid);

    // 四面体插值函数，对原始网格进行插值映射
    void InterpolateTetraMesh(GRDECLData &data, int samples=256);

    // 对延拓网格进行插值映射
    void InterpolateExpandTetraMesh(GRDECLData &data, ExpandInfo &expand_info, int samples=256);

    // vtk 文件写入函数
    bool WriteVTK(std::string filename, bool expand=false, bool cellData=true);

    // TODO: optimize expand data
    std::vector<Point3d> points; // mesh points
    std::vector<INDEX> boundary_lines; // 1D boundary lines, optional
    std::vector<INDEX> triangle_surfaces; // 2D triangles, optional
    std::vector<INDEX> tetrahedron_cells; // 3D tetrahedra

    // Multiple cell data
    std::vector<double> young;
    std::vector<double> poisson;
    std::vector<double> rockden;
    std::vector<double> poro; // cant interface in expand mesh
    std::vector<ExpandCellType> cell_types;

    // Point data
    std::vector<int> isInterface;

    // data size
    size_t basic_point_size;
    size_t basic_tetra_size;

    size_t expand_point_size;
    size_t expand_tetra_size;

    // expand info
    bool is_expand = false;

};

#endif // MESH3D_H